<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            overflow: auto;
            width: 100%;
            height: 1000px;
            background-color: aqua;
        }
    </style>
</head>

<body>
    <div>
        <button id="btn">
            提交
        </button>
    </div>
    <script>
        let btn = document.getElementById('btn')
        window.addEventListener('click',throttle(a))
        // var ticking = false
        // function click() {
        //     if (!ticking) {
        //         requestAnimationFrame(test)
        //         ticking = true
        //     }
        // }
        // function test() {
        //     console.log('我是requestAminmationFrame');
        //     ticking = false
        // }

        function a() {
            console.log(this);
            console.log('提交成功');
        }
        function throttle(fn, delay = 3000) {
            let pre = 0
            return function () {
                let time = Date.now()
                let arg = arguments
                if (time - pre >= delay) {
                    fn.call(this, arg)
                    pre = Date.now()
                }
            }
        }
    </script>
</body>

</html>